home *** CD-ROM | disk | FTP | other *** search
/ Internet Publisher's Toolbox 2.0 / Internet Publisher's Toolbox.iso / internet / ntserver / wtsource / config.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-08  |  2.5 KB  |  129 lines

  1.  
  2. /* Copyright (c) CNIDR (see file COPYRIGHT, included in this distribution) */
  3.  
  4. /* config.c: 
  5.  *  creates a header file with details on a machine's representation of 
  6.  *  numbers, alignment requirements, etc, etc.
  7.  */
  8.  
  9. #ifdef WIN32
  10. #include <process.h>
  11. #endif
  12.  
  13. #include <stdio.h>
  14.  
  15. #define SHORT_CODE 0
  16. #define INT_CODE   1
  17. #define LONG_CODE  2
  18. #define CHAR_CODE  3
  19.  
  20. typedef struct _short_test {
  21.   char c;
  22.   unsigned short s;
  23. } short_test;
  24.  
  25. typedef struct _long_test {
  26.   char c;
  27.   unsigned long l;
  28. } long_test;
  29.  
  30. typedef struct _int_test {
  31.   char c;
  32.   unsigned int i;
  33. } int_test;
  34.  
  35. #ifdef WIN32
  36. void main()
  37. #else
  38. int main()
  39. #endif 
  40. {
  41.  
  42.   short_test st;
  43.   long_test lt;
  44.   int_test it;
  45.  
  46.   int four_byte;
  47.   int two_byte;
  48.   int one_byte;
  49. #ifdef WIN32
  50.   unsigned long l;
  51.   unsigned char *cp;
  52. #else  
  53.   unsigned int i,*ip;
  54.   unsigned long l,*lp;
  55.   unsigned short s,*sp;
  56.   char c;
  57.   unsigned char *cp;
  58. #endif
  59.  
  60.  
  61.   if(sizeof(char) == 1) {
  62.     printf("#define ONE_BYTE char\n");
  63.     one_byte = CHAR_CODE;
  64.   } else {
  65.     fprintf(stderr,
  66.         "Error: chars are %d bytes long. Can't define ONE_BYTE\n",sizeof(char));
  67.     exit(1);
  68.   }
  69.  
  70.   if(sizeof(int) == 2) {
  71.     printf("#define TWO_BYTE int\n");
  72.     two_byte = INT_CODE;
  73.   } else {
  74.     if(sizeof(short) == 2) {
  75.       printf("#define TWO_BYTE short\n");
  76.       two_byte = SHORT_CODE;
  77.     } else {
  78.       fprintf(stderr,"Error: don't know how to define TWO_BYTE\n");
  79.       exit(1);
  80.     }
  81.   }
  82.  
  83.   if(sizeof(int) == 4) {
  84.     printf("#define FOUR_BYTE int\n");
  85.     four_byte = INT_CODE;
  86.   } else {
  87.     if(sizeof(long) == 4) {
  88.       printf("#define FOUR_BYTE long\n");
  89.       four_byte = LONG_CODE;
  90.      } else {
  91.        fprintf(stderr,"Error: don't know how to define FOUR_BYTE\n");
  92.      }
  93.   }
  94.     
  95.       
  96.   if(two_byte == SHORT_CODE) {
  97.     printf("#define TWO_BYTE_ALIGN %d\n",(int)(&st.s)-(int)(&st.c));
  98.   } else {
  99.     if (two_byte == INT_CODE) {
  100.       printf("#define TWO_BYTE_ALIGN %d\n",(int)(&it.i)-(int)(&it.c));
  101.     }
  102.   }
  103.   if(four_byte == INT_CODE) {
  104.     printf("#define FOUR_BYTE_ALIGN %d\n",(int)(&it.i)-(int)(&it.c));
  105.   } else {
  106.     if(four_byte == LONG_CODE) {
  107.       printf("#define FOUR_BYTE_ALIGN %d\n",(int)(<.l)-(int)(<.c));
  108.     }
  109.   }
  110.  
  111.   l=0xdeadbeef;
  112.  
  113.   
  114.   cp=(unsigned char*)&l;
  115.  
  116.   if(*cp == 0xde) {
  117.     printf("#define BIG_ENDIAN\n");
  118.   } else {
  119.     if(*cp == 0xef) {
  120.       printf("#define LITTLE_ENDIAN\n");
  121.       } else {
  122.     fprintf(stderr,"Error: can't find out byte order\n");
  123.     exit(1);
  124.       }
  125.   }
  126.   exit(0);
  127. }
  128.   
  129.